package none.rg.gantt.xmlio;


import none.rg.gantt.model.*;


/**
 * Class providing functionality of command-line utility. Package may be called
 * with two xml file names specified in the command line - it will read chart
 * from the first file, calculate the chart and write to the second file.
 * @author Rodion Gorkovenko
 */
public class CmdLineProcessor {
    
    
    private CmdLineProcessor(){}
    
    
    /**
     * Application entry point.
     * 
     * Should be called as "java -jar GanttChart.jar input.xml output.xml"
     */
    public static void main(String... args) {
        
        if (args.length < 2) {
            System.err.println("Please specify input and output xml files as parameters!");
            System.exit(1);
        } // if
        
        Chart chart = ChartLoader.getInstance().parseFile(args[0]);
        
        if (chart == null) {
            System.err.println("Error while reading input file!");
            System.exit(2);
        } // if
        
        try {
            ChartSaver.getInstance().writeToFile(chart, args[1]);
        } catch (Exception e) {
            System.err.println("Error while writing output file!");
            System.exit(3);
        } // catch
        
        System.out.println(args[0] + " => " + args[1] + "  -- processing completed!");
    } // main
    
    
} // CmdLineProcessor
